home *** CD-ROM | disk | FTP | other *** search
- unit StpKey2U;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, Menus;
-
- type
- TForm1 = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Edit1: TEdit;
- Edit2: TEdit;
- Edit3: TEdit;
- Edit4: TEdit;
- Edit5: TEdit;
- Edit6: TEdit;
- Edit7: TEdit;
- Edit8: TEdit;
- Label4: TLabel;
- procedure FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure FormKeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- function GetShiftState: TShiftState;
- var
- KeyState: TKeyboardState;
- begin
- Result := [];
- GetKeyboardState(KeyState);
- if KeyState[vk_Shift] and $80 <> 0 then Include(Result, ssShift);
- if KeyState[vk_Control] and $80 <> 0 then Include(Result, ssCtrl);
- if KeyState[vk_Menu] and $80 <> 0 then Include(Result, ssAlt);
- if KeyState[vk_LButton] and $80 <> 0 then Include(Result, ssLeft);
- if KeyState[vk_RButton] and $80 <> 0 then Include(Result, ssRight);
- if KeyState[vk_MButton] and $80 <> 0 then Include(Result, ssMiddle);
- end;
-
- function GetCtrlLetter(Ch: Char): Char;
- begin
- { Take away one less than the letter A }
- Result := Chr(Ord(Ch) - Ord(Pred('A')))
- end;
-
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if (Key = vk_F2) and (Shift = []) then
- begin
- Caption := 'F2 was pressed at ' + TimeToStr(Time);
- Key := 0
- end;
- end;
-
- procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
- var
- Shift: TShiftState;
- begin
- Shift := GetShiftState;
- { Check Escape }
- if (Key = Chr(vk_Escape)) and (Shift = []) then
- begin
- Color := RGB(Random(256), Random(256), Random(256));
- Key := #0
- end;
- { When Ctrl+letter is pressed, the character code is the }
- { position in the alphabet held by the uppercase letter }
- if (Key = GetCtrlLetter('S')) and (Shift = [ssCtrl]) then
- begin
- Application.Minimize;
- Key := #0
- end;
- if (UpCase(Key) = 'S') and (Shift = [ssAlt]) then
- begin
- Caption := 'Alt+S was pressed at ' + TimeToStr(Time);
- Key := #0
- end
- end;
-
- initialization
- Randomize
- end.
-